<template>
    <view class="bottom-bar buy-bottom-bar">
        <view class="action">
            <view class="action-item home-item" @click="easyGoHome">
                <image src="/static/icon/home.png"></image>
                <text>首页</text>
            </view>
            <!-- 		<view class="action-item" @click="goCart">
				<view class="icon-cart">
					<text class="badge" v-if="num>0">{{num>99?'99+':num}}</text>
					<image src="/static/icon/car.png"></image>
				</view>
				<text>购物车</text>
			</view> -->
            <view class="action-item" @click="favoriteFn">
                <view class="icon-cart">
                    <image :src="IsFavorite == 1 ? '/static/icon/like_a.png' : '/static/icon/like.png'"></image>
                </view>
                <text>收藏</text>
            </view>
        </view>
        <button
            class="btn btn-success"
            v-if="activity.Status && activity.timeStatus == 1 && activity.RemainQty"
            @click="addCart">
            立即购买
        </button>
        <button class="btn btn-success over" v-if="activity.Status && !activity.RemainQty">商品已售完</button>
        <button class="btn btn-success over" v-else-if="activity.Status && [0, 2].indexOf(activity.timeStatus) > -1">
            {{ activity.timeStatus == 0 ? "秒杀未开始" : "秒杀结束" }}
        </button>
    </view>
</template>

<script>
import { getCartTotal, getUserCarList } from "@/utils/cartUtil.js"
import { eventBus } from "@/utils/eventBus.js"
export default {
    props: ["IsFavorite", "activity"],
    data() {
        return {
            num: 0,
        }
    },
    mounted() {
        eventBus.$on("SET_CART", (msg) => {
            if (msg) {
                this.getCartNum(msg)
            }
        })
        getUserCarList((res) => {})
    },
    methods: {
        //获取购物车总数
        getCartNum(cartData) {
            this.num = cartData.length
            // getCartTotal(cartData, res => {
            // 	this.num = res.totalNum
            // })
        },
        //添加到购物车
        addCart() {
            this.$emit("showSku", "a")
        },
        favoriteFn() {
            this.$emit("favoriteFn")
        },
        //进入购物车
        goCart() {
            if (this.getSupplierMode() == 0) {
                this.easyGoTo("/pages/cart/cartTemp")
            } else if (this.getSupplierMode() == 1) {
                this.easyGoTo("/pages/supplier/cart/cartTemp")
            }
        },
    },
}
</script>

<style lang="scss">
.buy-bottom-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;

    .action {
        display: flex;
        flex: 3;
        flex-direction: row;
        margin-right: 20rpx;

        .action-item {
            display: flex;
            flex: 1;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            image {
                width: 44rpx;
                height: 44rpx;
            }
            text {
                margin-top: 6rpx;
            }
        }

        .home-item {
            text {
                // color: $app-color-main;
            }
        }

        .icon-cart {
            position: relative;
        }
    }

    .btn {
        flex: 3;
        color: #ffffff;
        background: $app-color-main;
        font-size: 32rpx;
        height: 80rpx;
        border-radius: 45rpx;
    }
    .btn.over {
        background-color: #b8b8b8 !important;
        border-color: #b8b8b8 !important;
    }
}
.badge {
    height: 14px;
    line-height: 14px;
    /* #ifdef APP-NVUE */
    flex: 1;
    /* #endif */
    margin-top: 5px;
    font-size: 10px;
    padding-left: 4px;
    padding-right: 4px;
    text-align: center;
    color: #fff;
    transform: translate(50%, -50%);
    background-color: #fe5128;
    border-radius: 9999px;
    position: absolute;
    top: 0;
    right: 0;
}
</style>
